import {Component, Inject, OnInit} from '@angular/core';
import {AccountService} from '../_services/account.service';
import {MAT_DIALOG_DATA, MatDialogRef} from '@angular/material/dialog';
import {AlertService} from '../_services/alert.service';

export interface DialogData {
  id: string;
}

@Component({templateUrl: 'dialog-confirm.component.html'})
export class DialogConfirmComponent implements OnInit{
  constructor(
    private accountService: AccountService,
    public dialogRef: MatDialogRef<DialogConfirmComponent>,
    @Inject(MAT_DIALOG_DATA) public data: DialogData,
    private alertService: AlertService
  ) {}

  ngOnInit(): void { }

  delete(): void {
    console.log('--------' + this.data.id);
    this.accountService.delete(this.data.id)
      .subscribe({
        next: (resp) => {
          if (resp.code === '200'){
            alert('删除成功');
          }
        },
        error: error => {
          this.alertService.error(error);
        }
      });
    this.dialogRef.close();
  }
}
